package com.example.tt;

import java.util.Observable;
import java.util.Observer;
import java.util.function.Supplier;

/**
 * @Author: wws
 * describe:
*/
public class MySupplier implements Observer, Supplier<String> {


    private String message;
    Observable observable;

    @Override
    public void update(Observable o, Object arg) {
        System.out.println("OB update+++++++++++++++++"+arg);
        this.observable = o;
        this.message = (String) arg;

        synchronized (this){
            notify();
        }

    }

    @Override
    public String get() {

        System.out.println("监听者启动");
        for (; ; ) {
            System.out.println( "OB执行一次");
            synchronized (this){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (message==null){
                continue;
            }
            if (message.equals("11")) {
                System.out.println("OB收到了");
                observable.deleteObserver(this);
                return "我他妈收到了";
            }
        }



    }
}
